package hellfire.game;

import java.util.Vector;

import android.util.Log;
import android.view.MotionEvent;
import hellfire.platform.graphics.ChickenRenderer;
import hellfire.platform.input.TouchListener;
import hellfire.system.graphics.GLRelVec2;
import hellfire.system.graphics.GLRenderer;
import hellfire.system.graphics.GLVec2;

public class Chicken
{
	private GLVec2 pos, vel;
	private static GLVec2 dim = new GLVec2(0.05f, 0.05f); 
	private static ChickenRenderer renderer = new ChickenRenderer();
	private Game game;
	
	public Chicken(Game game)
	{
		pos = new GLVec2(0.9,0);
		vel = new GLRelVec2(Math.random() - 0.5f, Math.random() - 0.5f);
		vel = vel.mul(0.03f);
		this.game = game;
	}
	
	public void gameFrame(Game game)
	{
		pos = pos.add(vel);
		
		//Log.d("R", "" + pos + " " + GLRenderer.ASP);
		GLVec2 vel_old = this.vel;
		if(pos.x() + dim.x() > 1) vel = vel.mul(-1, 1);
		if(pos.x() - dim.x() < -1) vel = vel.mul(-1, 1);
		if(pos.y() + dim.y() > 1) vel = vel.mul(1, -1);
		if(pos.y() - dim.y() < -1) vel = vel.mul(1, -1);
		if(vel != vel_old) //directions have changed
			pos = pos.add(vel);
	}
	
	public void setVelocity(GLVec2 vel)
	{
		this.vel = vel;
	}
	
	public void setPosition(GLVec2 pos)
	{
		this.pos = pos;
	}
	
	public GLVec2 getVelocity()
	{
		return this.vel;
	}
	
	public void Explode()
	{
		game.getChickenDebris().add(new ChickenDebris(this));
		game.getChickens().remove(this);
	}
	
	
	public GLVec2 getRenderPos()
	{
		return new GLRelVec2(pos);
	}
	
	public static GLVec2 getRenderDim()
	{
		return new GLRelVec2(dim);
	}
	
	public static GLVec2 getBoxDim()
	{
		return new GLRelVec2(dim).mul(2);
	}

	public ChickenRenderer getRenderer()
	{
		return renderer;
	}
	
}
